package com.self.liu.xp.base;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ServiceConfig {

    /* log */
    private static Logger logger = Logger.getLogger(ServiceConfig.class);

    private static Map<String, String> bussinessMap = null;

    private final static String FILE_PATH = "/service.properties";

    private static void init() {
        try {
            // 读取属性文件a.properties
            InputStream in = ServiceConfig.class.getResourceAsStream(FILE_PATH);
            Properties prop = new Properties();
            prop.load(in); /// 加载属性列表
            Iterator<String> it = prop.stringPropertyNames().iterator();
            Map<String, String> map = new HashMap<String, String>();
            while (it.hasNext()) {
                String key = it.next();
                map.put(key, prop.getProperty(key));
            }
            in.close();
            bussinessMap = map;
            logger.info("ServiceConfig加载成功。");
        } catch (Exception e) {
            logger.info("ServiceConfig加载失败。 case:" + e.getMessage());
        }
    }

    public static String getBusinessName(String code) {
        if (bussinessMap == null) {
            init();
        }
        return bussinessMap.get(code);
    }
}
